using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Umdf.SideShow.PocketPC;
using System.Net;
using Umdf.SideShow;
using Umdf.SideShow.Scf.Contents;
using Umdf.SideShow.Scf.ObjectModel;

namespace SideShowClient
{
    public partial class Form1 : Form
    {
        private ClientApplicationManager _appMgr;
        private ApplicationList _appList;
        private ScfNavigator _navigator;

        public Form1()
        {
            InitializeComponent();
            
            _appList = new ApplicationList();
            _appList.Dock = DockStyle.Fill;
            panel1.Controls.Add(_appList);
            
            _appMgr = new ClientApplicationManager(SideShowEndpoint.ScfFormatId);
            _appMgr.Connect(IPAddress.Parse("192.168.1.10"), 14000);
            _appList.SelectedApplicationChanged += new EventHandler(SelectedApplicationChanged);
            _appList.Applications = new List<SideShowApplication>(_appMgr.Applications);
            _appMgr.ListChanged += new EventHandler(ApplicationListChanged);

        }

        private void SelectedApplicationChanged(object sender, EventArgs e)
        {
            Invoke(new MethodInvoker(CreateNavigator));
        }

        private void CreateNavigator()
        {
            _navigator = new ScfNavigator(panel1, _appList.SelectedApplication, _appMgr);
        }

        private void ApplicationListChanged(object sender, EventArgs e)
        {
            this.BeginInvoke(new MethodInvoker(UpdateAppList));
        }

        private void UpdateAppList()
        {
            _appList.Applications = new List<SideShowApplication>(_appMgr.Applications);
        }

        private void btnBack_Click(object sender, EventArgs e)
        {
            if (_navigator != null)
            {
                _navigator.Back();
            }
        }

        
    }
}